import requests
import time
import execjs
from Crypto.Cipher import AES
from Crypto.Util import Padding
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
}
cookies = {
    "sessionid": "ao6ic6rmuqpb0fs0voqj1cr6c8xh87kr"
}
url = "https://match.yuanrenxue.cn/match/18data"

# hook 代码
'''
en_code = _[1][0]['CryptoJS']['AES'].encrypt;
_[1][0]['CryptoJS']['AES'].encrypt = function(text, key, mode){
aresult = en_code(text, key, mode).toString();
debugger;
return aresult
}
'''
with open(r'E:\Python\vscode\Crawlers\yuanrenxue\no18\task18_a.js', 'r') as f:
    js =execjs.compile(f.read())
result_list = []
for i in range(1,6):
    # 构建 AES 加密，生成请求参数v
    t = int(time.time())
    # hex_t  = hex(t)    # 输出16进制：0x68a6cc1c
    # 不要前面的0x
    hex_t = format(t, 'x')
    keys1 = hex_t * 2
    string_en = f"{i}|808m111,809m110,809m109,809d109,809u109"    # 鼠标坐标参数，随便选取一组作为待加密字符串
    # encrypt_data(page, t, key_v, data)
    params = js.call('encrypt_data',i,t,keys1,string_en)
    print(params)
    response = requests.get(url, headers=headers, cookies=cookies, params=params)
    datas = response.json()['data']
    for i in datas:
        result_list.append(i['value'])
print(sum(result_list))